]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
padOsd: Keep label coordinates in image coordinates
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 29 May 2020 14:59:46 +0000 (16:59 +0200)
committerFlorian Müllner <florian.muellner@gmail.com>
Fri, 29 May 2020 18:06:48 +0000 (18:06 +0000)
Apply the necessary transforms to map those coordinates to actor
positions in the allocate phase. This all fits since it's the place
where we do know the size the actor will have.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1290

js/ui/padOsd.js

index 8aadf5114a04eff0f4179c634fdab302d373f81b..3d825f9ed7497992f37e6f3ac5715f0c3a98d6d9 100644 (file)
@@ -411,9 +411,6 @@ var PadDiagram = GObject.registerClass({
     }
 
     _updateDiagramScale() {
-        if (this._handle == null)
-            return;
-
         [this._actorWidth, this._actorHeight] = this.get_size();
         let dimensions = this._handle.get_dimensions();
         let scaleX = this._actorWidth / dimensions.width;
@@ -426,6 +423,11 @@ var PadDiagram = GObject.registerClass({
         let [, natWidth] = child.get_preferred_width(natHeight);
         let childBox = new Clutter.ActorBox();
 
+        // I miss Cairo.Matrix
+        let dimensions = this._handle.get_dimensions();
+        x = x * this._scale + this._actorWidth / 2 - dimensions.width / 2 * this._scale;
+        y = y * this._scale + this._actorHeight / 2 - dimensions.height / 2 * this._scale;
+
         if (direction == LTR) {
             childBox.x1 = x;
             childBox.x2 = x + natWidth;
@@ -441,6 +443,9 @@ var PadDiagram = GObject.registerClass({
 
     vfunc_allocate(box) {
         super.vfunc_allocate(box);
+        if (this._handle === null)
+            return;
+
         this._updateDiagramScale();
 
         for (let i = 0; i < this._labels.length; i++) {
@@ -476,17 +481,6 @@ var PadDiagram = GObject.registerClass({
         cr.$dispose();
     }
 
-    _transformPoint(x, y) {
-        if (this._handle == null || this._scale == null)
-            return [x, y];
-
-        // I miss Cairo.Matrix
-        let dimensions = this._handle.get_dimensions();
-        x = x * this._scale + this._actorWidth / 2 - dimensions.width / 2 * this._scale;
-        y = y * this._scale + this._actorHeight / 2 - dimensions.height / 2 * this._scale;
-        return [Math.round(x), Math.round(y)];
-    }
-
     _getItemLabelCoords(labelName, leaderName) {
         if (this._handle == null)
             return [false];
@@ -514,9 +508,7 @@ var PadDiagram = GObject.registerClass({
             pos.y = this._imageHeight - pos.y;
         }
 
-        let [x, y] = this._transformPoint(pos.x, pos.y);
-
-        return [true, x, y, direction];
+        return [true, pos.x, pos.y, direction];
     }
 
     _getButtonLabels(button) {